<template>
      <!-- 档案记录区域汇总信息区域 -->
      <div class="flex" style="width: 25%;margin-right: 1%">
        <div novalidate class="flex auto" >
            <div class="row">
              <label class="col-md-2">归属期</label>
              <div class="col-md-4">
                <datepicker  placeholder="归属期"
                             v-model="model.startDate"
                             :value.sync="model.startDate"
                             :format="'yyyy-MM-dd'"
                ></datepicker>
              </div>
              <label class="col-md-1">至</label>
              <div class="col-md-4">
                <datepicker  placeholder="归属期"
                             v-model="model.endDate"
                             :value.sync="model.endDate"
                             :format="'yyyy-MM-dd'"
                ></datepicker>
              </div>
            </div>
            <div class="row" style="padding-top: 1%">
              <button class="btn btn-success col-md-offset-10" @click="searchAll()">查询</button>
            </div>
        </div>
        <div class="auto" id="nopadding-table">
          <partial-view v-ref:pv id="partial-view">
          <data-grid :model="model" partial='list' v-ref:grid style="flex: 1">
            <template partial='head'>
              <tr>
                 <th>抄表员</th>
                 <th>总户数</th>
                 <th>应抄</th>
                 <th>未下发</th>
                 <th>已抄表</th>
                 <th>未抄表</th>

              </tr>
            </template>
            <template partial='body'>
              <td>{{row.f_inputtor}}</td>
              <td>
                {{row.alls}}
              </td>
              <td><span class="btn btn-link"
                @click.stop="$parent.$parent.$parent.searchGather(row.f_inputtor, '', row.oughtnums)">{{row.oughtnums}}</span></td>
              <td><span class="btn btn-link"
                @click.stop="$parent.$parent.$parent.searchGather(row.f_inputtor, '未下发', row.weixiafa)">{{row.weixiafa}}</span></td>
              <td><span class="btn btn-link"
                @click.stop="$parent.$parent.$parent.searchGather(row.f_inputtor, '已抄表', row.yichao)">{{row.yichao}}</span></td>
              <td><span class="btn btn-link"
              @click.stop="$parent.$parent.$parent.searchGather(row.f_inputtor, '未抄表', row.weichao)">{{row.weichao}}</span></td>
            </template>
          </data-grid>
          </partial-view>
        </div>
      </div>
</template>

<script>
/**
*机表管理
*抄表管理组件
*/
import * as Util from '../../Util'
// import AppData from '../../stores/AppData'

export default {
  title: '抄表管理',
  props: ['sqlUrl', 'data'],
  data () {
    return {
      model: {
        startDate: '',
        endDate: '',
        rows: []
      }
    }
  },
  ready () {
    console.log('抄表管理。。。', this.sqlUrl)
    this.model.startDate = this.data.startDate
    this.model.endDate = this.data.endDate
    this.search()
  },
  methods: {
    search () {
      console.log('终于点进去查询，；', this.sqlUrl)
      let condition = '1=1'
      // 如果隶属总公司，不加任何判断
      if (!Util.f.parent.parent.name.includes('统一资源管理')) {
        condition += ` and f_filiale = '${Util.f.f_fengongsi}'`
      }
      this.$refs.pv.load(`${this.sqlUrl}`, {data: {startDate: this.model.startDate,endDate: this.model.endDate, condition: condition}}, {resolveMsg: null, rejectMsg: null}).then((res) => {
        this.model.rows = res.data
      })
    },
    searchAll () {
      this.search()
      this.$dispatch('refresh-child')
    },
    searchGather (inputtor, state, num) {
      console.log('左边查询', inputtor, state, num)
      this.$dispatch('refresh-child-condition', inputtor, state, num)
      // this.$refs.hand.searchGather(inputtor, state, num)
    }
  },
  watch: {
    'model.startDate' (val) {
      console.log('1111', val)
      this.data.startDate = val
    },
    'model.endDate' (val) {
      console.log('2222', val)
      this.data.endDate = val
    }
  }
}
</script>
<style lang="less">
  #partial-view div{
    height: auto;
  }
  #nopadding-table {
    th,
    td {
      padding: 8px 0px;
      text-align: center;
    }
  }
</style>
